<template>
  <el-dropdown trigger="click" :hide-on-click="false" class="openBut">
    <el-button type="primary" plain size="mini">
      订单操作<i class="el-icon-arrow-down el-icon--right" />
    </el-button>
    <el-dropdown-menu slot="dropdown" class="open">
      <el-dropdown-item>
        <el-button type="text" @click="Agency">受理</el-button>
      </el-dropdown-item>
      <el-dropdown-item>
        <el-button type="text" @click="Delete">删除</el-button>
      </el-dropdown-item>
      <el-dropdown-item>
        <el-button type="text" @click="Cancellation">作废</el-button>
      </el-dropdown-item>
      <el-dropdown-item>
        <el-button type="text" @click="cancelCancellation">取消作废</el-button>
      </el-dropdown-item>
      <el-dropdown-item>
        <el-button type="text" @click="cancelDelete">取消受理</el-button>
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import "./index.scss";
import {
  deleteOrder,
  assignmentStatus,
  cancelAcceptance,
  procRejection,
  cancelRejection,
} from "@/api/orderForm";
import { getToken } from "@/utils/auth";
export default {
  name: "Allorder",
  props: ["selectedNums", "displayOrders"],
  data() {
    return {
      // 弹出层动态名字
      canceValue: "",
      // 作废框内容
      getCancellation: "",
    };
  },
  methods: {
    // 取消受理
    cancelDelete() {
      var objselectedNums = {
        order_code: this.selectedNums,
        token: getToken("Cookie"),
      };
      cancelAcceptance(objselectedNums).then((res) => {
        var msg = res.msg;
        this.$nextTick(() => {
          this.displayOrders();
        });
        this.ContentSuccess(msg);
      });
    },
    // 取消作废,点击事件
    cancelCancellation() {
      this.canceValue = "取消作废";
      var serleList = {
        order_code: this.selectedNums,
        token: getToken("Cookie"),
      };
      cancelRejection(serleList).then((res) => {
        var msg = res.msg;
        this.$nextTick(() => {
          this.displayOrders();
        });
        this.ContentSuccess(msg);
      });
    },
    //  取消弹出层自定义样式
    getCan() {
      return (
        <div class="getCanceClass">
          <i class="el-icon-error"></i>{" "}
          <span>以下订单无法{this.canceValue}，请检查后重新选择！</span>
          <div class="checkinfo">
            <div class="checkinfo-one">原因说明：</div>
            <div class="checkinfo-tow">
              已下订单以运单，不能{this.canceValue}
            </div>
            <div class="checkinfo-therr">KD123456789</div>
          </div>
        </div>
      );
    },
    // 就是一个二级确认弹框（受理、作废、修改、删除）
    styleAmend() {
      this.$confirm(this.getCan(), "操作提醒", {
        confirmButtonText: "关闭",
        showCancelButton: false,
      })
        .then(() => {
          // 点击确定 情况样式动态名字
          this.canceValue = "";
        })
        .catch(() => {});
    },

    // 作废
    Cancellation() {
      this.$prompt("作废原因", "作废订单", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPlaceholder: "请输入作废原因",
        inputErrorMessage: "输入不能为空",
        inputValidtaor: (value) => {
          if (!value) {
            return "输入不能为空";
          }
        },
      })
        .then(({ value }) => {
          this.canceValue = "作废";
          var serleList = {
            order_code: this.selectedNums,
            token: getToken("Cookie"),
            rejection_reason: value,
          };
          procRejection(serleList).then((res) => {
            var msg = res.msg;
            this.$nextTick(() => {
              this.displayOrders();
            });
            this.ContentSuccess(msg);
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消作废",
          });
        });
    },

    // 点击修改
    Revamp() {
      this.$confirm("修改订单", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 点击受理
    Agency() {
      this.$confirm("确定要受理所选订单吗?", "受理订单", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          var objselectedNums = {
            order_code: this.selectedNums,
            token: getToken("Cookie"),
          };
          assignmentStatus(objselectedNums).then((res) => {
            var msg = res.msg;
            this.$nextTick(() => {
              this.displayOrders();
            });
            this.ContentSuccess(msg);
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消受理",
          });
        });
    },
    ContentSuccess(msg) {
      this.$message({
        message: msg,
        type: "success",
      });
      this.$nextTick(() => {
        this.displayOrders();
      });
    },
    locationReload() {
      location.reload();
    },
    // 点击删除按钮
    async Delete() {
      var objselectedNums = {
        order_code: this.selectedNums,
        token: getToken("Cookie"),
      };
      let result = await deleteOrder(objselectedNums);
      this.$nextTick(() => {
        this.displayOrders();
      });
      this.locationReload();
    },
  },
};
</script>
